package com.hnevc.xiaoming.shijianactivity;

import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.hnevc.xiaoming.R;

import java.util.Timer;
import java.util.TimerTask;

public class EventHanding extends AppCompatActivity {

    private int data = 0;
    private Timer timer;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.eh_layout);

        initData();
    }

    private void initData() {

//        timer = new Timer();
//        timer.schedule(new TimerTask() {
//            @Override
//            public void run() {
//                back = false;
//                Log.e("TAG", "run: dddddddddddddddddddddddddddddd" );
//            }
//        },0,2000);

    }

    @Override
    protected void onStop() {
//        timer.cancel();
        super.onStop();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        data ++;
        if (keyCode == KeyEvent.KEYCODE_BACK){
            Toast.makeText(this, "连续点击两次退出界面", Toast.LENGTH_SHORT).show();
            if (data < 2) {
                return true;
            }
        }else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP){
            Toast.makeText(this, "音量增加", Toast.LENGTH_SHORT).show();
        }

        return super.onKeyDown(keyCode, event);
    }
}
